package com.lagou.mysql.task01;

import java.sql.*;
import java.util.Scanner;

public class EmployeeTest {
    public static void main(String[] args) throws SQLException{

        // 1.创建连接
        Connection connection = JDBCutils.getCollection();



        //2. 编写SQL
        String sql = "select * from employee where ename = ? and gender = ? ";

        //设置参数
        Scanner sc = new Scanner(System.in);
        String ename = sc.nextLine();
        String gender = sc.nextLine();

        PreparedStatement preparedStatement = connection.prepareStatement(sql);
        preparedStatement.setString(1,ename);
        preparedStatement.setString(2,gender);
        ResultSet resultSet = preparedStatement.executeQuery();

        //3.处理结果集
        while (resultSet.next()) {

            int id1 = resultSet.getInt("id");
            String ename1 = resultSet.getString("ename");
            String gender1 = resultSet.getString("gender");
            Double salary1 = resultSet.getDouble("salary");
            Double bonus1 = resultSet.getDouble("bonus");
            Date join_date1 = resultSet.getDate("join_date");

            System.out.println(id1 + " - " + ename1 + " - " + gender1 + " - " + salary1+ " - " + bonus1 + " - " + join_date1);
        }

        //5.释放资源
        JDBCutils.close(connection,preparedStatement);

    }
}
